using System;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using Sanelib.Dto;

namespace Common.Commands.LeadCommands
{
    public class AddAnonymousLead : ICommand
    {
        public string Name { get; set; }
        public string CompanyName { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }
        public string Description { get; set; }

        public Guid Id { get; set; }

        public Guid? GetAggregateId()
        {
            return null;
        }

        public ErrorResult Validate()
        {
            var validationResult = new ErrorResult();

            if (!string.IsNullOrWhiteSpace(Name) && Name.Length > 128)
                validationResult.AddError("Name", " entered exceeds the maximum length 128");

            if (string.IsNullOrWhiteSpace(Name))
                validationResult.AddError("Name", "should not empty.");

            if (!string.IsNullOrWhiteSpace(CompanyName) && CompanyName.Length > 128)
                validationResult.AddError("Company Name", " entered exceeds the maximum length 128");

            if (string.IsNullOrWhiteSpace(CompanyName))
                validationResult.AddError("CompanyName", "should not empty.");

            if (!string.IsNullOrWhiteSpace(Email) && Email.Length > 128)
                validationResult.AddError("Email", " entered exceeds the maximum length 128");

            if (Email.IsEmpty())
                validationResult.AddError("Email", "should not be empty");
            else
            {
                if (Email.IsNotEmpty() && Formatter.EmailId(Email) != true)
                    validationResult.AddError("Email", "should be correct formate. (xxxxx@xxx.xx)");
            }

            if (!string.IsNullOrWhiteSpace(Description) && Description.Length > 2048)
                validationResult.AddError("Description"," entered exceeds the maximum lenght 2048");

            return validationResult;
        }
    }
}